<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="/wesite/view/common/base.jsp" %>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>手机号注册</title>
    <%@ include file="/wesite/view/common/common.jsp" %>
    <style type="text/css">
        html, body {
            background: #f2f2f2;
        }
        .loginbox.signbox{
            margin:0;
        }

    </style>
</head>
<body>
<div class="loginbox signbox">
    <div class="login-input">
        <div class="input-text"><span class="text-tit">手机号</span><input id="phone" name="phone" type="number" placeholder="请输入11位数手机号码">
        </div>
        <div class="input-text"><span class="text-tit">验证码</span><input class="code" id="smscode" type="number"
                                                               placeholder="请输入验证码"><span id="yzmbtn" onclick="tosendsms()"
                                                                                       class="send">获取验证码</span></div>
        <div class="input-text"><span class="text-tit">密码</span><input type="password" name="pwd" placeholder="请输入密码"></div>

    </div>
    <input type="button" onclick="toregister()" value="注册">
    <div class="agreement">注册即同意<span onclick="javascript:window.location.href = ctx + '/we/article/agreement'">《用户协议》</span>
    </div>
    <div class="signbox-b"><span
            onclick="javascript:window.location.href = ctx + '/we/sign/accountRegister'">用户名注册</span></div>
</div>
</body>
<script type="text/javascript" src="${ctx}/website/js/common.js"></script>
<script type="text/javascript" src="${ctx}/website/js/sms.js"></script>
<script type="text/javascript" src="${webctx}/script/aui-toast.js"></script>
<script type="text/javascript">
    //校验密码
    function isPassword(str) {
        var isPassword = /^[a-zA-Z0-9_]{6,16}$/;
        var bl = isPassword.test(str);
        return bl;
    }

    //手机号注册
    function toregister() {
        var subing = false;
        var checked = true;
        if (!$w.isMobile($("#phone").val())) {
            new auiToast().fail({
                title: "请输入手机号",
                duration: 2000
            });
            checked = false;
        }

        if ($("#smscode").val() == "") {
            new auiToast().fail({
                title: "验证码不能为空",
                duration: 2000
            });
            checked = false;
        }

        if ($("[name='pwd']").val() == '' || $("[name='pwd']").val().length < 6 || $("[name='pwd']").val().length > 16) {
            new auiToast().fail({
                title: "密码在6-16位字符之间",
                duration: 2000
            });
            checked = false;
        } else if (!isPassword($("[name='pwd']").val())) {
            new auiToast().fail({
                title: "密码必须由字母数字下划线组成",
                duration: 2000
            });
            checked = false;
        }

        if (!subing && checked) {
            subing = true;
            $w.httpRequest({
                url: apiroot + "/we/user/register",
                data: {
                    "mobile": $("#phone").val(),
                    "pwd": $("[name='pwd']").val(),
                    "smscode": $("#smscode").val(),
                    "regtype": "phone"
                },
                ok: function (ret) {
                    var user = ret.Data;
                    try {
                        sessionStorage.setItem("_newreg_", "true");
                        sessionStorage.removeItem("_curUrl_");
                        new auiToast().success({
                            title: "注册成功",
                            duration: 2000
                        });
                    } catch (e) {
                    }
                    window.location.href = user;
                },
                fail: function (ret) {
                    if (ret.MsgCode == '2') {
                        new auiToast().fail({
                            title: "该手机号已被注册",
                            duration: 2000
                        });
                    }
                    else if (ret.MsgCode == '3') {
                        new auiToast().fail({
                            title: "短信验证码错误",
                            duration: 2000
                        });
                    }
                    else {
                        new auiToast().fail({
                            title: "注册失败",
                            duration: 2000
                        });
                    }
                    return false;
                },
                all: function () {
                    subing = false;
                }
            })
        }
    }

    //发送验证码
    function tosendsms() {
        if (!$w.isMobile($("#phone").val())) {
            new auiToast().fail({
                title: "请输入手机号",
                duration: 2000
            });
        } else {
            $w.httpRequest({
                url: apiroot + "/user/checkloginname",
                method: "post",
                data: {"loginname": $("#phone").val()},
                ok: function (ret) {
                    new auiToast().fail({
                        title: "该手机号已被注册",
                        duration: 2000
                    });
                }, fail: function (ret) {
                    sendsms($("#phone").val(), 'reg', 'yzmbtn');
                    return false;
                }
            })
        }
    }



    $(window).resize(function(){
        var hig = parseInt($(".loginbox").outerHeight(true));//div的高度包括margin
        var hig2 = parseInt($(".signbox-b").height());        //底部内容块的高度
        var hig3 = parseInt($(".signbox-b").css("bottom"));
        var hig4 = hig + hig2 + hig3;
        var hig_h = document.documentElement.clientHeight ;     //屏幕可视高度

        if(hig4 > hig_h){
            $(".signbox-b").hide();
        }else{
            $(".signbox-b").show();
        }

    });

</script>
</html>